<?php 
$this->load->view('admin/layout/head', array('title'=>"类别管理",'nav'=>'product'), FALSE);
switch ($this->session->admin_language) {
	case 'chinese':
		$prefix = '';
		break;
	case 'english':
		$prefix = 'en_';
		break;
	default:
		$prefix = '';
		break;
}
?>

<div id="container">
<ul class="nav nav-tabs" id="subject-tab">
	<li class="active"><a href="javascript:;"><?php echo isset($category)? $this->lang->line('edit_category') : $this->lang->line('create_category') ?></a></li>
</ul>
<?= form_open('', [
	'class' => 'form-inline deal-from container-fluid no-padding',
	'id' => 'category-form'
]); ?>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('category_title') ?></label>
		<div class="form-group">
			<input type="text" name="title" class="form-control" value="<?= set_value('title', empty($category['title']) ? '' : $category['title']) ?>" style="width: 300px">
		</div>
		<?= form_error('title', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('en_category_title') ?></label>
		<div class="form-group">
			<input type="text" name="en_title" class="form-control" value="<?= set_value('en_title', empty($category['en_title']) ? '' : $category['en_title']) ?>" style="width: 300px">
		</div>
		<?= form_error('en_title', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('icon_name') ?></label>
		<div class="form-group">
			<input type="text" class="form-control" name="image" value="<?= set_value('image', empty($category['image']) ? '' : $category['image']) ?>">
		</div>
		<?= form_error('image', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('parent_category') ?></label>
		<div class="form-group">
			<select name="parent_id" id="" class="form-control">
				<option value="0"><?= $this->lang->line('parent_category') ?></option>
				<?php foreach ($parent_categories as $cate):?>
				<option value="<?php echo $cate['id']?>" <?php if(isset($category) && $cate['id'] == $category['parent_id']) echo 'selected' ?>><?php echo $cate[$prefix.'title'] ?></option>
				<?php endforeach; ?>
			</select>
		</div>
		<?= form_error('parent_id', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('ad_image') ?></label>
		<div class="form-group" >
			<a href="javascript:;" class="btn btn-primary" id='up-btn1'><?= $this->lang->line('choose_image') ?></a>
			<input type="hidden" name='ad' id="ad" value="<?= set_value('ad', empty($category['ad']) ? '' : $category['ad']) ?>">
			<div id="up-container1">
				<?php if(set_value('ad', empty($category['ad']) ? '' : $category['ad'])): ?>
				<img src="<?= set_value('ad', empty($category['ad']) ? '' : $category['ad']) ?>" alt="" style="max-width: 600px; max-height: 100px"/>
				<?php endif; ?>
			</div>
		</div>
		<?= form_error('ad', '<div class="text-danger">', '</div>') ?>
	</div>
	
	<div class="mt-20">
		<label for=""><?= $this->lang->line('sort') ?></label>
		<div class="form-group" >
			<input type="text" name="sort" class="form-control" value="<?= set_value('sort', empty($category['sort']) ? '' : $category['sort']) ?>" style="width: 100px">
		</div>
		<?= form_error('sort', '<div class="text-danger">', '</div>') ?>
	</div>

	<div style="padding-left:110px" class="mt-20">
      <button class="btn btn-primary save"><?= $this->lang->line('save') ?></button>
      <a onclick="window.history.go(-1)" class="btn btn-default cancel"><?= $this->lang->line('cancel') ?></a>
    </div>

<?= form_close() ?>
</div>


<?php 
$js_array = array(
	'/assets/plupload/plupload.full.min.js'
	);
$this->load->view('admin/layout/footer',array('js'=>$js_array));
?>
<script type="text/javascript">

	$(function(){
		uploadImg('up-btn1',function(img){
			$('#up-container1').html('<img src="'+img+'" style="max-width: 600px; max-height: 100px"/>');
			$('#ad').val(img);
		});
	})
	$('.save').click(function(event) {
		
		if(!$('input[name=title]').val()){
			alert('请填写分类名称');
			return;
		}
	});
</script>